/*
编解码
*/
package util

import "unsafe"

type ICodecBaseType interface {
	~int32 | ~int64 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 | ~int16
}

// Byte2Base 解码
func Byte2Base[T ICodecBaseType](src []byte) T {
	var instance T
	size := unsafe.Sizeof(instance)
	return (*(*[]T)(unsafe.Pointer(Byte2Slice(src, int(size)))))[0]
}

// Base2Byte 编码
func Base2Byte[T ICodecBaseType](src T) []byte {
	var instance T
	size := unsafe.Sizeof(instance)
	return Slice2Byte(*(*Slice)(unsafe.Pointer(&([]T{src}))), int(size))
}
